#import "Controller.h"

@implementation Controller
- (void)awakeFromNib {
	ping = [[PingFM alloc] init];
	[ping setDelegate:self];
	
	[ping setUserKey:@"6254396bc50911d5da2280a12ebf04df-1239988260"];
	
	if ([ping validate]) {
		NSLog(@"Validated succesfully");
		services = [[NSArray alloc] initWithArray:[ping services]];
		triggers = [[NSArray alloc] initWithArray:[ping triggers]];
	}
	postMethods = [[NSArray alloc] initWithObjects:@"default", @"status", @"blog", @"microblog", nil];
}
- (IBAction)ping:(id)sender {
    BOOL success = [ping simplePost:[pingField stringValue] withPostMethod:@"default"];
	if (success)
		NSLog(@"posted");
}

- (IBAction)startKeyModal:(id)sender {
    
}

- (IBAction)stopKeyModal:(id)sender {
    
}

- (void)requestWillBegin {
	[progressIndicator startAnimation:self];
}

- (void)requestDidEnd {
	[progressIndicator stopAnimation:self];
}

- (void)controlTextDidChange:(NSNotification *)aNotification {
	int length = [[pingField stringValue] length];
	[charactersLabel setStringValue:[NSString stringWithFormat:@"%d of 140", length]];
	
	if (length > 0) {
		[promptLabel setHidden:YES];
	} else {
		[promptLabel setHidden:NO];
	}
}
@end
